package game.java3D.bibliotheque;

import java.awt.Color;

import javax.media.j3d.LineArray;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;

public class Cercle extends Shape3D {

	public Cercle(int nbSegments, Color color) {

		int nbPoints = nbSegments * 2;
		LineArray la = new LineArray(nbPoints, LineArray.COORDINATES
				| LineArray.COLOR_3);

		Point3f points[] = new Point3f[nbPoints];
		Color3f colors[] = new Color3f[nbPoints];

		for (int i = 0; i < nbPoints; i++) {
			points[i] = new Point3f(1f * (float) Math.cos(2 * i * Math.PI
					/ nbPoints), 1f * (float) Math.sin(2 * i * Math.PI
					/ nbPoints), 0f);

			colors[i] = new Color3f(color);
			if (i % 2 != 0 && i < nbPoints - 1) {
				i++;
				points[i] = points[i - 1];
				colors[i] = colors[i - 1];
			}
		}
		la.setCoordinates(0, points);
		la.setColors(0, colors);
		this.setGeometry(la);
	}
}
